package shemes;

import gui.GuiLine;
import gui.GuiScheme;

import java.awt.Point;
import java.util.ArrayList;

import components.*;
import gui.GuiLabel;

public class Exec4 {

    private static NOT NOT1, NOT2, NOT3, NOT4, NOT5, NOT6, NOT7;
    private static XOR XOR1;
    private static OR OR1, OR2;
    private static MP MX7, MX8, MX9;
    private static IntToBools IBUS1bits;
    private static IntToInt IBUS1low4, IBUS1low3;
    private static GuiScheme gui;

    public static GuiScheme getGui() {
        return gui;
    }

    public static void init() {
        NOT1 = new NOT();
        NOT2 = new NOT();
        NOT3 = new NOT();
        NOT4 = new NOT();
        NOT5 = new NOT();
        NOT6 = new NOT();
        NOT7 = new NOT();
        XOR1 = new XOR();
        OR1 = new OR();
        OR2 = new OR();
        MX7 = new MP(8);
        MX8 = new MP(8);
        MX9 = new MP(2);
        IBUS1bits = new IntToBools(8, 8);
        IBUS1low4 = new IntToInt(16, 4);
        IBUS1low3 = new IntToInt(16, 3);


    }

    public static void connect() {

        NOT1.setInputPin(0, Exec2.PSWZ());
        XOR1.setInputPin(0, Exec2.PSWN());
        XOR1.setInputPin(1, Exec2.PSWV());
        NOT2.setInputPin(0, XOR1.getOut(0));
        OR1.setInputPin(0, XOR1.getOut(0));
        OR1.setInputPin(1, Exec2.PSWZ());
        NOT3.setInputPin(0, OR1.getOut(0));
        OR2.setInputPin(0, Exec2.PSWC());
        OR2.setInputPin(1, Exec2.PSWZ());
        NOT4.setInputPin(0, OR2.getOut(0));
        NOT5.setInputPin(0, Exec2.PSWC());
        NOT6.setInputPin(0, Exec2.PSWV());
        NOT7.setInputPin(0, Exec2.PSWN());

        MX7.setInputPin(0, Exec2.PSWZ());//eql
        MX7.setInputPin(1, NOT1.getOut(0));
        MX7.setInputPin(2, Exec2.PSWN());//neg
        MX7.setInputPin(3, NOT7.getOut(0));
        MX7.setInputPin(4, Exec2.PSWV());//ovf
        MX7.setInputPin(5, NOT6.getOut(0));
        MX7.setInputPin(6, Exec2.PSWC());//car
        MX7.setInputPin(7, NOT5.getOut(0));
        MX7.setCtrl(0, IBUS1bits.getOut(0));
        MX7.setCtrl(1, IBUS1bits.getOut(1));
        MX7.setCtrl(2, IBUS1bits.getOut(2));

        MX8.setInputPin(0, NOT3.getOut(0));
        MX8.setInputPin(1, NOT2.getOut(0));
        MX8.setInputPin(2, XOR1.getOut(0));
        MX8.setInputPin(3, OR1.getOut(0));
        MX8.setInputPin(4, NOT4.getOut(0));
        MX8.setInputPin(5, NOT5.getOut(0));
        MX8.setInputPin(6, Exec2.PSWC());
        MX8.setInputPin(7, OR2.getOut(0));
        MX8.setCtrl(0, IBUS1bits.getOut(0));
        MX8.setCtrl(1, IBUS1bits.getOut(1));
        MX8.setCtrl(2, IBUS1bits.getOut(2));

        MX9.setInputPin(0, MX7.getOut(0));
        MX9.setInputPin(1, MX8.getOut(0));
        MX9.setCtrl(0, IBUS1bits.getOut(3));

        IBUS1bits.setInputPin(0, Bus1.IBUS1());
        IBUS1low4.setInputPin(0, Bus1.IBUS1());
        IBUS1low3.setInputPin(0, Bus1.IBUS1());


    }

    public static void gui() {
        GuiLine line; // Pomocna promenljiva
        gui = new GuiScheme("src/images/Exec4.png");

        ArrayList<ArrayList<Point>> sections;
        ArrayList<Point> points;


        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 41));
        points.add(new Point(237, 41));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 41));
        points.add(new Point(196, 58));
        points.add(new Point(203, 58));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(230, 58));
        points.add(new Point(237, 58));
        sections.add(points);
        line = new GuiLine(sections, NOT1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 81));
        points.add(new Point(130, 81));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWN());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 92));
        points.add(new Point(130, 92));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWV());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(150, 86));
        points.add(new Point(237, 86));
        sections.add(points);
        line = new GuiLine(sections, XOR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(158, 86));
        points.add(new Point(158, 126));
        points.add(new Point(167, 126));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 87));
        points.add(new Point(196, 103));
        points.add(new Point(203, 103));
        sections.add(points);
        line = new GuiLine(sections, XOR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 103));
        points.add(new Point(237, 103));
        sections.add(points);
        line = new GuiLine(sections, NOT2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 137));
        points.add(new Point(168, 137));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(188, 132));
        points.add(new Point(237, 132));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 132));
        points.add(new Point(196, 149));
        points.add(new Point(203, 149));
        sections.add(points);
        line = new GuiLine(sections, OR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 149));
        points.add(new Point(237, 149));
        sections.add(points);
        line = new GuiLine(sections, NOT3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 171));
        points.add(new Point(129, 171));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 183));
        points.add(new Point(130, 183));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(150, 177));
        points.add(new Point(237, 177));
        sections.add(points);
        line = new GuiLine(sections, OR2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(196, 177));
        points.add(new Point(196, 194));
        points.add(new Point(203, 194));
        sections.add(points);
        line = new GuiLine(sections, OR2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 194));
        points.add(new Point(237, 194));
        sections.add(points);
        line = new GuiLine(sections, NOT4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 41));
        points.add(new Point(487, 41));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 41));
        points.add(new Point(445, 58));
        points.add(new Point(453, 58));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 58));
        points.add(new Point(487, 58));
        sections.add(points);
        line = new GuiLine(sections, NOT5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 86));
        points.add(new Point(487, 86));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 86));
        points.add(new Point(445, 103));
        points.add(new Point(453, 103));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWV());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 103));
        points.add(new Point(487, 103));
        sections.add(points);
        line = new GuiLine(sections, NOT6.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 132));
        points.add(new Point(487, 132));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 133));
        points.add(new Point(445, 149));
        points.add(new Point(453, 149));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWN());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 149));
        points.add(new Point(487, 149));
        sections.add(points);
        line = new GuiLine(sections, NOT7.getOut(0));
        gui.addLine(line);


        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(89, 389));
        points.add(new Point(89, 491));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(91, 389));
        points.add(new Point(91, 491));
        sections.add(points);
        line = new GuiLine(sections, Bus1.IBUS1());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(558, 389));
        points.add(new Point(558, 491));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(560, 389));
        points.add(new Point(560, 491));
        sections.add(points);
        line = new GuiLine(sections, Bus1.IBUS2());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(92, 453));
        points.add(new Point(389, 453));
        sections.add(points);
        line = new GuiLine(sections, IBUS1low4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(237, 452));
        points.add(new Point(237, 420));
        sections.add(points);
        line = new GuiLine(sections, IBUS1low3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(222, 415));
        points.add(new Point(222, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(2));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(237, 417));
        points.add(new Point(237, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(1));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(253, 415));
        points.add(new Point(253, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(390, 453));
        points.add(new Point(478, 453));
        points.add(new Point(478, 341));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(3));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 415));
        points.add(new Point(374, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(2));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(389, 416));
        points.add(new Point(389, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(1));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(404, 415));
        points.add(new Point(404, 408));
        sections.add(points);
        line = new GuiLine(sections, IBUS1bits.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(389, 452));
        points.add(new Point(389, 421));
        sections.add(points);
        line = new GuiLine(sections, IBUS1low3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 389));
        points.add(new Point(209, 389));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 370));
        points.add(new Point(209, 370));
        sections.add(points);
        line = new GuiLine(sections, NOT1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 351));
        points.add(new Point(209, 351));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWN());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 332));
        points.add(new Point(209, 332));
        sections.add(points);
        line = new GuiLine(sections, NOT7.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 313));
        points.add(new Point(209, 313));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWV());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 294));
        points.add(new Point(209, 294));
        sections.add(points);
        line = new GuiLine(sections, NOT6.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 275));
        points.add(new Point(209, 275));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(202, 256));
        points.add(new Point(209, 256));
        sections.add(points);
        line = new GuiLine(sections, NOT5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 389));
        points.add(new Point(360, 389));
        sections.add(points);
        line = new GuiLine(sections, NOT3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 370));
        points.add(new Point(360, 370));
        sections.add(points);
        line = new GuiLine(sections, NOT2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 351));
        points.add(new Point(360, 351));
        sections.add(points);
        line = new GuiLine(sections, XOR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 332));
        points.add(new Point(360, 332));
        sections.add(points);
        line = new GuiLine(sections, OR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 313));
        points.add(new Point(360, 313));
        sections.add(points);
        line = new GuiLine(sections, NOT4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 294));
        points.add(new Point(360, 294));
        sections.add(points);
        line = new GuiLine(sections, NOT5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 275));
        points.add(new Point(360, 275));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(353, 256));
        points.add(new Point(360, 256));
        sections.add(points);
        line = new GuiLine(sections, OR2.getOut(0));
        gui.addLine(line);
        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(266, 323));
        points.add(new Point(285, 323));
        points.add(new Point(285, 228));
        points.add(new Point(436, 228));
        points.add(new Point(436, 304));
        points.add(new Point(455, 304));
        sections.add(points);
        line = new GuiLine(sections, MX7.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(417, 323));
        points.add(new Point(455, 323));
        sections.add(points);
        line = new GuiLine(sections, MX8.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(500, 313));
        points.add(new Point(508, 313));
        sections.add(points);
        line = new GuiLine(sections, MX9.getOut(0));
        gui.addLine(line);

         // LABELE:
        gui.addLabel(new GuiLabel(103, 385, Bus1.IBUS1()));
        gui.addLabel(new GuiLabel(565, 459, Bus1.IBUS2()));
        gui.addLabel(new GuiLabel(163, 466, IBUS1low4.getOut(0)));
        gui.addLabel(new GuiLabel(242, 444, IBUS1low3.getOut(0)));
        gui.addLabel(new GuiLabel(394, 444, IBUS1low3.getOut(0)));
        
    }

    public static Pin brpom() {
        return MX9.getOut(0);
    }
}
